//
//  BCProjectIntroductionRiskLevelTableCell.m
//  GSBlockChain
//
//  Created by guoshikeji_a on 2018/11/23.
//  Copyright © 2018年 guoshikeji. All rights reserved.
//

#import "BCProjectIntroductionRiskLevelTableCell.h"

static CGFloat BCProjectIntroductionRiskLevelTableCellTopBottomPadding = 5.0;


@interface BCProjectIntroductionRiskLevelTableCell ()

@property (nonatomic, strong) UILabel *riskLabel;

@property (nonatomic, strong) UILabel *yieldLabel;

@end

@implementation BCProjectIntroductionRiskLevelTableCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupSubviews];
    }
    return self;
}

- (void)setupSubviews {
    self.riskLabel = [UILabel new];
    self.riskLabel.textColor = [UIColor qmui_colorWithHexString:@"#525252"];
    self.riskLabel.font = [UIFont systemFontOfSize:13 weight:UIFontWeightRegular];
    self.riskLabel.numberOfLines = 0;
    [self.contentView addSubview:self.riskLabel];
    [self.riskLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView).offset(BCProjectIntroductionRiskLevelTableCellTopBottomPadding);
        make.left.mas_equalTo(self.contentView);
        make.width.mas_equalTo(self.contentView);
    }];
    //
    self.yieldLabel = [UILabel new];
    self.yieldLabel.textColor = [UIColor qmui_colorWithHexString:@"#525252"];
    self.yieldLabel.font = [UIFont systemFontOfSize:13 weight:UIFontWeightRegular];
    self.yieldLabel.numberOfLines = 0;
    [self.contentView addSubview:self.yieldLabel];
    [self.yieldLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.riskLabel.mas_bottom).offset(5.0);
        make.left.mas_equalTo(self.contentView);
        make.width.mas_equalTo(self.contentView);
        make.bottom.mas_equalTo(self.contentView).offset(-BCProjectIntroductionRiskLevelTableCellTopBottomPadding);
    }];
}


- (void)setRiskLevel:(BCProjectIntroductionRiskLevelModel *)riskLevel {
    _riskLevel = riskLevel;
    //
    NSString *levelFull = riskLevel.levelFull.length?riskLevel.levelFull:@"";
    NSString *levelRule = riskLevel.levelRule.length?riskLevel.levelRule:@"";
    NSString *risk = [NSString stringWithFormat:@"%@ %@",levelFull,levelRule];
    NSMutableAttributedString *riskAttri = [[NSMutableAttributedString alloc] initWithString:risk];
    if (levelRule.length) {
        NSRange range = [risk rangeOfString:levelRule];
        if (range.location!=NSNotFound) {
            [riskAttri addAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12 weight:UIFontWeightRegular],NSForegroundColorAttributeName:[UIColor qmui_colorWithHexString:@"#ADADAD"]} range:range];
        }
    }
    self.riskLabel.attributedText = riskAttri;
    //
    self.yieldLabel.text = riskLevel.yield;
}


@end
